/*
 * @Descripttion:
 * @Author: YuZhenJing
 * @Date: 2019-12-04 14:00:22
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-03-08 19:20:07
 */

// 登录并设置用户信息
export function loginByUserName({ commit }, userinfo) {
  const _this = this._vm
  return new Promise((resolve, reject) => {
    const loginByUsername = _this.$coreHtml.post('login', userinfo)
    loginByUsername
      .then(data => {
        const resultData = data.returnData
        _this.$auth.hostUrl.set(resultData.hostUrl)
        _this.$auth.menuInfo.set(resultData.menuList)
        _this.$auth.token.set(resultData.tokenValue)
        _this.$auth.userInfo.set(resultData.userInfo)
        resolve(data)
      })
      .catch(error => {
        reject(error)
      })
  })
}

// 退出系统
export function submitLoginOut() {
  const _this = this._vm
  return new Promise((resolve, reject) => {
    const loginOut = _this.$coreHtml.get('logout')
    loginOut
      .then(() => {
        resolve()
      })
      .catch(error => {
        reject(error)
      })
  })
}
